package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponDiscountDTO;
import com.tianji.promotion.domain.dto.OrderCourseDTO;
import com.tianji.promotion.domain.query.UserCouponQuery;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.service.IUserCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户领取优惠券的记录，是真正使用的优惠券信息 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-22
 */
@RestController
@RequestMapping("/user-coupons")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "用户优惠券接口")
public class UserCouponController {
    private final IUserCouponService userCouponService;

    @PostMapping("/{id}/receive")
    @ApiOperation("用户领取发放中的优惠券")
    public void addUserCoupon(@PathVariable Long id) {
        userCouponService.addUserCoupon(id);
    }
    @ApiOperation("兑换码兑换优惠券接口")
    @PostMapping("/{code}/exchange")
    public void exchangeCoupon(@PathVariable("code") String code){
        userCouponService.exchangeCoupon(code);
    }
    @ApiOperation("查询我的优惠券列表")
    @GetMapping("/page")
    public PageDTO<CouponPageVO> queryMyCouponPage(UserCouponQuery query) {
        return userCouponService.queryMyCouponPage(query);
    }
    @ApiOperation("查询我的优惠券可用方案")
    @PostMapping("/available")
    public List<CouponDiscountDTO> findDiscountSolution(@RequestBody List<OrderCourseDTO> orderCourses){
        return userCouponService.findDiscountSolution(orderCourses);
    }

}
